package com.lanou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.bean.*;
import com.lanou.mapper.*;
import com.lanou.service.PageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/14.
 */
@Service
public class PageServiceImpl implements PageService {
    @Resource
    private RoleInfoMapper roleInfoMapper;
    @Resource
    private AdminInfoMapper adminInfoMapper;
    @Resource
    private CostMapper costMapper;
    @Resource
    private AccountMapper accountMapper;
    @Resource
    private ServiceMapper serviceMapper;

    @Override
    public PageInfo<RoleGuanLiBean> selectRoleByPage(Integer pageNo, Integer pageSize) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<RoleGuanLiBean> roleGuanLiBeanList = roleInfoMapper.selectadminInfo();
        PageInfo<RoleGuanLiBean> roleInfoPageInfo = new PageInfo<RoleGuanLiBean>(roleGuanLiBeanList);

        return roleInfoPageInfo;
    }

    @Override
    public PageInfo<AdminModule> selectAdminByPage(Integer pageNo, Integer pageSize) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<AdminModule> adminModuleList = adminInfoMapper.selectAllAdminInfo();
        PageInfo<AdminModule> adminModulePageInfo = new PageInfo<AdminModule>(adminModuleList);
        return adminModulePageInfo;
    }

    @Override
    public PageInfo<Cost> selectCostByPage(Integer pageNo, Integer pageSize) {

        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<Cost> costList = costMapper.selectAllCost();
        PageInfo<Cost> costPageInfo = new PageInfo<Cost>(costList);
        return costPageInfo;
    }


    @Override
    public PageInfo<Account> selectAccountByPage(Integer pageNo, Integer pageSize) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<Account> accountList = accountMapper.getAllAccountInfo();
        PageInfo<Account> accountPageInfo = new PageInfo<Account>(accountList);
        return accountPageInfo;
    }

    @Override
    public PageInfo<com.lanou.bean.Service> selectServiceByPage(Integer pageNo, Integer pageSize) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<com.lanou.bean.Service> serviceList = serviceMapper.selectAllService();
        PageInfo<com.lanou.bean.Service> servicePageInfo = new PageInfo<com.lanou.bean.Service>(serviceList);
        return servicePageInfo;
    }

    @Override
    public PageInfo<com.lanou.bean.Service> selectServiceBySearch(Integer pageNo, Integer pageSize, String login_name, String idcard_no, String real_name) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<com.lanou.bean.Service> serviceList = serviceMapper.selectServiceBySearch(login_name, idcard_no, real_name);
        PageInfo<com.lanou.bean.Service> servicePageInfo = new PageInfo<com.lanou.bean.Service>(serviceList);
        return servicePageInfo;
    }

    @Override
    public PageInfo<Account> accountSearch(Integer pageNo, Integer pageSize, String idcardNo,
                                           String realName, String loginName, int status) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<com.lanou.bean.Account> accountList = accountMapper.accountSearch(idcardNo, realName, loginName, status);
        PageInfo<com.lanou.bean.Account> accountPageInfo = new PageInfo<com.lanou.bean.Account>(accountList);
        return accountPageInfo;
    }

    @Override
    public PageInfo<AdminModule> searchAdminInfo(Integer pageNo, Integer pageSize, String name) {
        //当前页
        pageNo = pageNo==null? 1:pageNo;
        //每页显示几条数据
        pageSize = pageSize == null?5:pageSize;
        PageHelper.startPage(pageNo,pageSize);
        List<AdminModule> admintList = adminInfoMapper.searchAdminInfo(name);
        PageInfo<com.lanou.bean.AdminModule> adminPageInfoList = new PageInfo<com.lanou.bean.AdminModule>(admintList);
        return adminPageInfoList;
    }


}
